using System.Collections.Generic;
using Tycho.Parser.Peg;

namespace Tycho.Parser.Syntax {
    public class ProductionLookup {
        public bool IsFirst;
        public Language DefaultLanguage;
        public Dictionary<Language, Production<ParseContext>> Productions;
        public Production<ParseContext> NextProduction;

        public ProductionLookup (Language defaultLanguage, Dictionary<Language, Production<ParseContext>> productions, Production<ParseContext> nextProduction) {
            IsFirst = true;
            DefaultLanguage = defaultLanguage;
            Productions = productions;
            NextProduction = nextProduction;
        }

        public Production<ParseContext> this [Language language] {
            get {
                if (language == null) {
                    language = DefaultLanguage;
                }

                if (language == DefaultLanguage && IsFirst) {
                    return NextProduction;
                }

                return Productions[language];
            }
        }
    }
}